package com.example.qixin0314.bean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.qixin0314.R;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class listAdapter extends RecyclerView.Adapter<listAdapter.listHolder> {
    private List<listModel> data;
    private Context context;

    public listAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<listModel> data) {
        this.data = data;
    }

    @NonNull
    @NotNull
    @Override
    public listHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        return new listHolder(LayoutInflater.from(context).inflate(R.layout.list_itrm,null));
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull listHolder holder, int position) {
        holder.text_item.setText(data.get(position).getName());

    }

    @Override
    public int getItemCount() {
        return null!=data?data.size():0;
    }

    class listHolder extends RecyclerView.ViewHolder{
        TextView text_item;

        public listHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            text_item=itemView.findViewById(R.id.text_item);
        }
    }
}
